package com.gao.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    private ApiInfo apiInfo(){

//        源码中没有set方法 仅能使用构造器
        Contact contact = new Contact("高总", "https://space.bilibili.com/7222890", "1181810576@qq.com");

        return new ApiInfo(
                "高总的API接口文档",
                "实验性质的api",
                "1.0",
                "urn:tos",// url链接
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }

    @Bean
    public Docket docket(Environment environment){

//        设置要显示Swagger的环境
        Profiles profiles = Profiles.of("dev");

//        获取项目的环境
        boolean flag = environment.acceptsProfiles(profiles);

        System.out.println(flag);


        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                //enable() 是否启用Swagger
                .enable(flag)
                .select()
                //RequestHandlerSelectors 配置要扫描接口的方式
                //basePackage() 扫描指定包
                //any() 全部
                //none() 不扫描
                //withClassAnnotation() 扫描类上的注解，参数是一个注解的反射对象
                //withMethodAnnotation() 扫描方法上的注解，
                .apis(RequestHandlerSelectors.basePackage("com.gao.modules"))//指定扫描那些包的接口
                .paths(PathSelectors.any())
                .build();


    }




}
